var pageParam = getParam();
var view = new Vue({
    el: '#view',
    data: {
        imgurl: imgurl,
        m: {
            id: pageParam['id'],
            url: imgurl + pageParam['video'],
            cover: imgurl + pageParam['cover'],
            // burn: 1,
            // packet: 10,
            // see: pageParam['see'],
            // type: 1,
            burn: pageParam['burn'],
            packet: pageParam['packet'],
            see: pageParam['see'],
            type: pageParam['type'],
        },
        vip: 0,
        videoShow: 0, // 0不显示 1显示 2播放中
    },
    methods: {
        // 查看图片
        lookImg: function (type) {
            var _this = this;
            var videoDom = document.getElementById('video-url');
            var videoSource = document.getElementById('video-url-mp4');
            if (type == 0) {
                _this.videoShow = 2;
                videoSource.src = _this.m.url;
                videoDom.load();
                videoDom.play();
                burnImg();
            } else if (type == 1) {
                payImg(function () {
                    _this.m.packet = 0;
                    _this.videoShow = 2;
                    videoSource.src = _this.m.url;
                    videoDom.load();
                    videoDom.play();
                });
            } else if (type == 2) {
                payImg(function () {
                    _this.m.packet = 0;
                    _this.videoShow = 2;
                    videoSource.src = _this.m.url;
                    videoDom.load();
                    videoDom.play();
                    burnImg();
                });
            } else {
                _this.videoShow = 2;
                videoSource.src = _this.m.url;
                videoDom.load();
                videoDom.play();
            }
        }
    }
})

var touserid = pageParam['uid'] || myuserid;

getUserInfo();
// 获取用户信息
function getUserInfo() {
    _getUser(function (ret) {
        view.vip = ret.result.is_vip;
    })
}

showVideo();
// 渲染视频
function showVideo() {
    if (view.m.type == 0) {
        view.videoShow = 0;
        view.m.url = '';
        pageParam['video'] = '';
    } else {
        view.videoShow = 1;
    }
}

// 焚毁照片
function burnImg(callback) {
    var time = view.vip == 0 ? 2000 : 6000;
    var id = view.m.id;
    view.m.burn = 0;
    setTimeout(function () {
        view.m.type = 0;
        view.videoShow = 0;
        view.m.url = '';
        pageParam['video'] = '';
    }, time)
    _ajax('Home/User/burn', function (ret, err) {
        _log(JSON.stringify(ret));
    }, {
        user_id: touserid,
        to_user: myuserid,
        id: id,
    })
}

// 付费
function payImg(callback) {
    var data = {
        user_id: touserid,
        to_user: myuserid,
        img_id: view.m.id,
        price: view.m.packet,
    };
    var obj = {
        msg: '该视频的价格为' + view.m.packet + 'USDT，请确认您的操作。',
    }
    _confirm(obj, function (bIndex) {
        if (bIndex == 1) {
            _ajax('Home/User/packetimg', function (ret) {
                _log(JSON.stringify(ret));
                if (ret.code == 200) {
                    _msg('支付成功，眼睛不要离开屏幕，视频马上出来~');
                    if (typeof callback == 'function') {
                        callback();
                    }
                } else {
                    _msg(ret.msg);
                }
            }, data)
        }
    })
}
